package edu.temple.mobile.adapters;

import java.util.List;

import edu.temple.mobile.R;
import edu.temple.mobile.objectClasses.BusRoutes;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class BusRoutesAdapter extends ArrayAdapter<BusRoutes> {

	int resource;
	String response;
	Context context;
	//Initialize adapter
	public BusRoutesAdapter(Context context, int resource, List<BusRoutes> items) {
		super(context, resource, items);
		this.resource=resource;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		LinearLayout alertView;
		//Get the current alert object
		BusRoutes al = getItem(position);
		

		//Inflate the view
		if(convertView==null)
		{
			alertView = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi;
			vi = (LayoutInflater)getContext().getSystemService(inflater);
			vi.inflate(resource, alertView, true);
		}
		else
		{
			alertView = (LinearLayout) convertView;
		}
		//Get the text boxes from the listitem.xml file
		TextView routeShortName =(TextView)alertView.findViewById(R.id.txtRouteShortName);
		TextView routeLongName =(TextView)alertView.findViewById(R.id.txtRouteLongName);

		//Assign the appropriate data from our alert object above
		//A huge if-else block to convert the routes that contain a letter, from their encoded integer "id" to their proper letter 
				//designations
				if(al.route_short_name == 500){
					routeShortName.setText("Broad Street Orange Line (Owl Service)");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 501){
					routeShortName.setText("Broad Stret Orange Line");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 502){
					routeShortName.setText("C");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 503){
					routeShortName.setText("G");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 504){
					routeShortName.setText("HXH");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 505){
					routeShortName.setText("J");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 506){
					routeShortName.setText("K");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 507){
					routeShortName.setText("L");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 508){
					routeShortName.setText("LUCY");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 509){
					routeShortName.setText("LUCY");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 510){
					routeShortName.setText("Market Frankford Line");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 511){
					routeShortName.setText("Market Frankford Line (Owl Service)");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 512){
					routeShortName.setText("Norristown High Speed Line");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_short_name == 513){
					routeShortName.setText("R");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_long_name.equals("South Phila to 7th & Spring Garden ")){
					routeShortName.setText("47M");
					routeLongName.setText(al.route_long_name);
				}else if(al.route_long_name.equals("Yeadon-Darby To Center  City       ") && al.route_id == 9839){
					routeShortName.setText("13B");
					routeLongName.setText(al.route_long_name);
				}else{
				routeShortName.setText(Integer.toString(al.route_short_name));
				routeLongName.setText(al.route_long_name);
				}
		return alertView;
	}

}